<template>
  <div class="user-container">
    <div class="slect-group">
      <van-dropdown-menu>
      <van-dropdown-item v-model="active_id" :options="mnueItemList" />
    </van-dropdown-menu>
    </div>
    <div class="user-header">
      <div class="ranking-group ranking-one" v-if="fristUser">
        <img class="ranking-img" :src="fristUser.avatarUrl" alt="">
        <img class="ranking-gj" :src=" `${publicPath}source/img/haungguan11.png`" alt="">
        <div class="ranking-title">{{fristUser.nickname}}：{{fristUser.avg_scoring?Number(fristUser.avg_scoring).toFixed(1):0}}分</div>
      </div>
      <div class="ranking-group ranking-two" v-if="secondUser">
        <img class="ranking-img" :src="secondUser.avatarUrl" alt="">
        <div class="ranking-title">{{secondUser.nickname}}：{{secondUser.avg_scoring?Number(secondUser.avg_scoring).toFixed(1):0}}分</div>
      </div>
      <div class="ranking-group ranking-three" v-if="thirdUser">
        <img class="ranking-img" :src="thirdUser.avatarUrl" alt="">
        <div class="ranking-title">{{thirdUser.nickname}}：{{thirdUser.avg_scoring?Number(thirdUser.avg_scoring).toFixed(1):0}}分</div>
      </div>
    </div>
    <div style="position: relative;height: 120px;" v-if="userDetail">
      <div class="ranking-frist-group">
        <span class="yj-col-1 ranking-list-num">我</span>
        <span class="yj-col-2 ranking-list-img">
          <img class="ranking-img" :src="userDetail.avatarUrl" alt="">
        </span>
        <span class="yj-col-5 ranking-list-name">排名：{{userDetail.rank}}</span>
        <span class="yj-col-3 ranking-list-number">{{userDetail.avg_scoring?Number(userDetail.avg_scoring).toFixed(1):0}}</span>
        <span class="yj-col-1  ranking-list-jf">
          <img :src=" `${publicPath}source/img/jifen_icon.png`" alt="">
        </span>
      </div>
    </div>
    <div class="ranking-list-group" v-for="(item, index) in tableList" :key="index">
      <div class="ranking-list">
        <span class="yj-col-1 ranking-list-num">{{item.rank}}</span>
        <span class="yj-col-2 ranking-list-img">
          <img class="ranking-img" :src="item.avatarUrl" alt="">
        </span>
        <span class="yj-col-5 ranking-list-name">{{ item.nickname }}</span>
        <span class="yj-col-3 ranking-list-number1">{{ item.avg_scoring?Number(item.avg_scoring).toFixed(1):0 }}</span>
        <span class="yj-col-1  ranking-list-jf">
          <img :src=" `${publicPath}source/img/jifen_icon.png`" alt="">
        </span>
      </div>
    </div>
  </div>
</template>

<script>
import { Cell, CellGroup, Toast, DropdownMenu, DropdownItem } from 'vant';
export default {
  components: {
    [Cell.name]: Cell, [CellGroup.name]: CellGroup, [DropdownMenu.name]: DropdownMenu, [DropdownItem.name]: DropdownItem
  },
  data: function () {
    return {
      mnueItemList: [],
      mnueItemIndex: 0,
      active_id:'',
      tableList:[],
      rankList:[],
      userDetail:null,
      fristUser:null,
      secondUser:null,
      thirdUser:null,
      publicPath: process.env.NODE_ENV === 'development'?'/':'/weChatApp/'
    };
  },
  mounted() {
    this.itemListMethod();
  },
  methods: { 
    itemListMethod(){
      this.$http
        .post(this.$API.GET_ACTIVE_LIST)
        .then((res) => {
          if (res.code == 1) {
            let list = Array.isArray(res.data.list) ? res.data.list : [],arr=[];
            list.forEach(item=>{
              arr.push({text:item.title,value:item.id})
            })
             this.mnueItemList=arr;
             if(arr.length>0){
              this.active_id=arr[0].value
              this.initAjaxMethod()
             }
          }
        });
    },
    //列表加载
    initAjaxMethod() {
      Toast.loading({ message: "加载中...", forbidClick: true });
      this.$http
        .post(this.$API.USER_RANK_LIST,{active_id:this.active_id})
        .then((res) => {
          Toast.clear();
          if (res.code == 1) {
            let list = Array.isArray(res.data) ? res.data : [],arr=[],userid=localStorage.getItem('YF_USER_INFOS_ID'),rank=[],user=null;
            list.forEach(item=>{
              if(item.member_id == userid){
                user=item;
              }
              if(item.rank == 1 || item.rank == 2 || item.rank == 3){
                if(item.rank == 1)this.fristUser=item;
                if(item.rank == 2)this.secondUser=item;
                if(item.rank == 3)this.thirdUser=item;
              }else{
                if(item.member_id != userid){
                  arr.push(item)
                }
              }
            })
            console.log('user',user);
            this.tableList=arr;
            this.userDetail=user;
            this.rankList=rank;
          }
        });
    },
  },
};
</script>

<style lang="less">
.user-container {
  position: relative;
  .user-header {
    height: 460px;
    background: url("../../../assets/img/yundonglishi_image.png") center
      no-repeat;
    background-size: 100% 100%;
    position: relative;
  }

  .slect-group{
    position: absolute;
    top:0;
    left:0;
    width: 100%;
    z-index: 100;
    .van-dropdown-menu__bar{
      background: transparent;
    }
    .van-dropdown-menu__title{
      font-size: 0.3rem;
      color:#fff;
    }
  }

  .van-cell{
      background: rgba(255, 255, 255, 0.2);
    }

  .header-mnue {
    background: #ffffff;
    border-radius: 32px;
    background-color: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    padding: 2px;
    font-size: 0;
  }

  .header-mnue-group {
    width: 25%;
    height: 32px;
    padding: 4px 2px;
  }

  .header-mnue-item {
    height: 100%;
    width: 100%;
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 400;
  }

  .header-mnue-item-active {
    font-weight: 500;
    color: #333333;
    background-color: #fff;
  }

  .header-mnue-item-important {
    color: #ffffff;
  }

  .ranking-group {
    position: absolute;
    padding: 15px;
    background-color: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
  }

  .ranking-img {
    border-radius: 50%;
  }

  .ranking-gj {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translate(-50%, -100%);
    width: 44px;
    height: 27px;
  }

  .ranking-one {
    top: 32%;
    left: 50%;
    transform: translateX(-50%);
    width: 110px;
    height: 110px;
  }

  .ranking-one .ranking-img {
    width: 80px;
    height: 80px;
  }

  .ranking-title {
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translate(-50%, 100%);
    white-space: nowrap;
    font-size: 14px;
    font-weight: 500;
    color: #ffffff;
    line-height: 20px;
  }

  .ranking-two {
    top: 44%;
    left: 8%;
    width: 100px;
    height: 100px;
  }

  .ranking-three {
    top: 53%;
    right: 6%;
    width: 100px;
    height: 100px;
  }

  .ranking-two .ranking-img,
  .ranking-three .ranking-img {
    width: 70px;
    height: 70px;
  }

  .ranking-jb-group {
    position: absolute;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
  }

  .ranking-jb-two-img {
    width: 60px;
    height: 60px;
  }

  .ranking-jb-text {
    display: flex;
    align-items: center;
    position: absolute;
    bottom:0;
    left:50%;
    transform: translate(-50%,30px);
  }

  .ranking-jb-text span {
    font-size: 18px;
    font-weight: bold;
    color: #ffffff;
    line-height: 21px;
    white-space: nowrap;
  }

  .ranking-jb-text img {
    width: 20px;
    height: 20px;
    margin-left: 4px;
  }

  .ranking-jb-one-img {
    width: 70px;
    height: 70px;
  }

  .ranking-jb-three-img {
    width: 50px;
    height: 50px;
  }

  .ranking-jb-one {
    top: 55%;
    left: 50%;
    transform: translateX(-50%);
  }

  .ranking-jb-two {
    top: 67%;
    left: 12%;
  }

  .ranking-jb-three {
    top: 77%;
    right: 10%;
  }

  .ranking-frist-group {
    height: 74px;
    background: linear-gradient(270deg, rgba(255, 255, 255) 0%, #a9c9d2 100%);
    border-radius: 8px 8px 0px 0px;
    padding: 16px 16px 0 16px;
    display: flex;
    align-items: center;
    position: absolute;
    top: -16px;
    width: 100%;
    z-index: 2;
  }

  .ranking-list-num {
    font-size: 15px;
    font-weight: 500;
    color: #4a4a4a;
  }

  .ranking-list-img {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .ranking-list-img img {
    width: 38px;
    height: 38px;
  }

  .ranking-list-name {
    font-size: 16px;
    font-weight: 500;
    color: #1c1c1c;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
  }

  .ranking-list-number {
    font-size: 22px;
    font-weight: bold;
    color: #ff6f4d;
    text-align: right;
  }

  .ranking-list-number1 {
    font-size: 22px;
    font-weight: bold;
    color: #1c1c1c;
    text-align: right;
  }

  .ranking-list-jf {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .ranking-list-jf img {
    width: 20px;
    height: 20px;
  }

  .ranking-list-group {
    padding: 0 16px;
  }

  .ranking-list {
    height: 68px;
    display: flex;
    align-items: center;
    border-bottom: 1px solid #f5f5f5;
  }
}
</style>